package com.sy.servlet;

import com.alibaba.fastjson.JSON;
import com.sy.entity.Emp;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import java.io.IOException;
import java.util.*;

@WebServlet("/test1")
public class TestServlet1 extends HttpServlet {
    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
        res.setContentType("application/json;charset=utf-8");

        Emp emp1=new Emp();
        emp1.setEmpno(1);
        emp1.setEname("jack");
        emp1.setHobbies(Arrays.asList("唱歌","跳舞"));

        Emp emp2=new Emp();
        emp2.setEmpno(2);
        emp2.setEname("Tom");
        emp2.setHobbies(Arrays.asList("健身","跳舞"));

        List<Emp> emps=new ArrayList<>();
        emps.add(emp1);
        emps.add(emp2);


        Map<String,Object> map=new HashMap<>();
        map.put("第一个",emp1);
        map.put("第二个",emp2);



        //int r=1/0;

        //res.getWriter().print(JSON.toJSONString(map));
        res.getWriter().print(JSON.toJSONString(emps,true));

    }
}
